<template>
<div class="content-center">
  <div class="content-cotainer border-box">
    <div class="content-breadcrumb">
      <el-breadcrumb separator="/" class="breadcrumb">
        <el-breadcrumb-item :to="{ path: '/' }">审计报告</el-breadcrumb-item>
        <el-breadcrumb-item>审计报告列表</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="audit-content">
      <div class="centent-title">
        <span>{{title}}</span>
      </div>
      <!-- 页面内容 -->
      <div class="centent-inner" style="padding:15px;">
        <div>
          <el-row>
            <el-button type="primary" size="small" @click="addreport">新建报告提纲</el-button>
            <el-button :disabled="disdelete" type="primary" size="small" @click="deletereport">{{buttonNm}}</el-button>
            <!-- <el-button type="primary" @click="dialogTableVisible = true" size="small">查看审核意见</el-button>
            <el-button type="primary" size="small">共享</el-button> -->
            <el-button type="success" size="small" @click="syncreport">同步</el-button>
            <el-button type="primary" size="small">导入</el-button>
          </el-row>
          <br>
          <el-dialog title="查看审核意见" :visible.sync="dialogTableVisible">
            <el-table :data="gridData" size="mini">
              <el-table-column type="index" label="序号" width="100"></el-table-column>
              <el-table-column prop="suggestName" label="审计报告名称" width="200">
                <template slot-scope="scope">
                  <el-button type="text" @click="lookSuggest">{{scope.row.suggestName}}
                  </el-button>
                </template>
              </el-table-column>
              <el-table-column prop="suggestPeople" label="审核人" width="100"></el-table-column>
              <el-table-column prop="suggestStatus" label="审核状态"></el-table-column>
            </el-table>
            <!--新建报告提纲页面的分页-->
            <el-pagination style="margin-top: 10px;" background layout="prev, pager, next" :total="50">
            </el-pagination>
            <br>
            <div v-if="showSuggest">
              <el-row>
                <el-col :span="24">
                  <div class="grid-content bg-purple">
                    <span class="my-font-height">报告审核意见</span>
                  </div>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">这个报告写的非常完美，没毛病了，感觉可以转密了</el-col>
              </el-row>
            </div>
          </el-dialog>
          <!--新建报告提纲的dialog-->
          <el-dialog class="content-dialog" title="选择模板" :visible.sync="newReportOutline" center>
            <el-select style="width: 100%" class="content-dialog-select" pos v-model="value" placeholder="请选择">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
            <span slot="footer" class="dialog-footer">
              <el-button @click="newReportOutline = false">取 消</el-button>
              <el-button type="primary" @click="reportOutline">确 定</el-button>
            </span>
          </el-dialog>
          <el-table size="mini" :data="tableData" 
          @selection-change="selectedchange" border style="width: 100%">
            <el-table-column type="selection" width="40px">
            </el-table-column>
            <!-- <el-table-column v-if="false" prop="tId" label="主键ID" width="10">
            </el-table-column> -->
            <el-table-column type="index" label="序号" align="center" width="50">
            </el-table-column>
            <el-table-column prop="auditRptfileNm" align="center" label="审计报告名称">
              <template slot-scope="scope">
                <el-button type="text" @click="didi(scope.row.tId,scope.row.RptFileName)">
                  {{scope.row.auditRptfileNm}}
                </el-button>
              </template>
            </el-table-column>
            <el-table-column prop="rcrdCrtpsnNm" align="center" label="编制人"></el-table-column>
            <el-table-column prop="rcrdCrtTm" align="center" label="编制日期"></el-table-column>
            <el-table-column prop="rcrdUptTm" align="center" label="报告同步日期"></el-table-column>
            <el-table-column prop="lcsCd" align="center" label="审核状态">
              <template slot-scope="scope">
                <el-button type="text" @click="opinion(scope.row.auditRptfileId,scope.row.auditRptfileNm)">
                <span v-if="scope.row.lcsCd === '0'">编制中</span>
                <span v-else-if="scope.row.lcsCd === '1'">审核中</span>
                <span v-else-if="scope.row.lcsCd === '2'">审核通过</span>
                <span v-else-if="scope.row.lcsCd === '3'">审核不通过</span>
                <span v-else-if="scope.row.lcsCd === '4'">废弃</span>
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <!-- 审计报告列表分页-->
          <el-pagination style="margin-top: 10px;" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage4" :page-sizes="[100, 200, 300, 400]" :page-size="100" layout="total, sizes, prev, pager, next, jumper" :total="400">
          </el-pagination>
        </div>
        <div v-if="myflag" id="reportDetails">
          <el-row>
            <el-col :span="24">
              <div class="grid-content bg-purple">
                <span class="my-font-height">{{mytitle}}</span>
              </div>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">{{reportContent}}</el-col>
          </el-row>
        </div>
      </div>
    </div>
  </div>
</div>
</template>

<script>
import axios from 'axios'
export default {
  data() {
    return {
      buttonNm: '废弃',
      disdelete: false,
      selectedlist: [], // 勾选行
      currentPage1: 5,
      currentPage2: 5,
      currentPage3: 5,
      currentPage4: 4,
      title: '审计报告列表',
      options: [],
      value: '',
      showSuggest: false,
      gridData: [{
        suggestName: '报告初稿0812',
        suggestPeople: '张三丰',
        suggestStatus: '审核完成'
      }, {
        suggestName: '报告初稿0812',
        suggestPeople: '杨过',
        suggestStatus: '审核完成'
      }, {
        suggestName: '报告初稿0812',
        suggestPeople: '谢逊',
        suggestStatus: '审核中'
      }],
      dialogTableVisible: false,
      newReportOutline: false,
      myflag: false,
      mytitle: '',
      reportContent: '',
      tableData: []
    }
  },
  mounted () {
    // 查询审计报告列表
    this.tableData = []
    let info = {
      "auditGrpId": '11',
      "auditPrjId": '22'
    }
    axios.post('http://localhost:7111/tOesRpt/queryTOesRptFileList',info).then((response) => {
      console.log(response)
      if (response.data){
        this.tableData = response.data
      }
      console.log(this.tableData)
    }).catch((response) => {
      console.log(response)
    })
  },
  methods: {
    selectedchange (val) {
      this.selectedlist = val
      if (val && Array.isArray(val) && val.length > 0) {
        // 如果数组中存在审核中/审核通过/审核不通过的,则按钮置灰
        if (val.findIndex(item => item.lcsCd === '1' || item.lcsCd === '2' || item.lcsCd === '3') !== -1) {
          console.log('1111111')
          this.disdelete = true
          return false
        } else if (val.every(item =>item.lcsCd === '0')) {
          console.log('2222222')
          this.buttonNm = '废弃'
          this.disdelete = false
          return false
        } else if (val.every(item =>item.lcsCd === '4')) {
          console.log('3333333')
          this.buttonNm = '启用'
          this.disdelete = false
          return false
        } else if (val.some(item =>item.lcsCd === '4') && val.some(item =>item.lcsCd === '4')) {
          console.log('444444444')
          this.disdelete = true
          return false
        }
      } else {
        console.log('5555555')
        this.disdelete = true
        return false
      }
    },
    // 查询审计报告
    selectreport() {
      let info = {
      "auditGrpId": '11',
      "auditPrjId": '22'
      }
      axios.post('http://localhost:7111/tOesRpt/queryTOesRptFileList',info).then((response) => {
        console.log(response)
        this.tableData = response.data
        console.log(this.tableData)
      }).catch((response) => {
        console.log(response)
      })
    },
    // 删除报告
    // deletereport () {
    //   if (this.selectedlist && Array.isArray(this.selectedlist) && this.selectedlist.length >=0) {
    //     // 没有勾选行
    //     if (this.selectedlist.length === 0) {
    //       this.$message.warning('请至少勾选一行')
    //     // 勾选一行或多行
    //     } else if (this.selectedlist.length > 0) {
    //       this.selectedlist.forEach(element => {
    //             this.tableData.splice(element.index, 1, {deleteflag: 1})
    //         })
    //       let templist = []
    //       this.tableData.forEach(item => {
    //         if (!item.deleteflag) {
    //           templist.push(item)
    //         }
    //       })
    //       this.tableData = templist
    //     }
    //   }
    // },
      // 删除报告
      deletereport(){
      let auditRptfileIds = this.selectedlist.map(item => item.auditRptfileId)
      if(this.selectedlist.length > 0){
        this.$confirm('是否' + this.buttonNm + '该记录?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(() => {
          axios.post('http://localhost:7111/tOesRpt/deleteTOesRptByIds',auditRptfileIds)
                  .then(response => {
                    this.$message({
                      type: 'success',
                      message: response.data.resultMsg
                    });
                    this.selectreport();
                  }, err => {
                  })
                  .catch((error) => {
                  })
        }).catch(action => {
        });
      }else{
        this.$message({
          type: 'info',
          message: '请至少选择一条数据'
        });
      }
    },
    //同步报告
    syncreport(){
      let info = {
        "userId": "0001",
        "projectId": "0002",
        "auditGroupId": "0003",
        "wenshuType":"001110",
        "auditRptfileIds":this.selectedlist.map(item => item.auditRptfileId)
      }
      if(this.selectedlist.length > 0){
        this.$confirm('开始同步审计报告初稿, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(() => {
          axios.post('http://localhost:7111/syncFromICBC/syncFile',info)
                  .then(response => {
                    this.$message({
                      type: 'success',
                      message: response.data.resultMsg
                    });
                    this.selectreport();
                  }, err => {
                  })
                  .catch((error) => {
                  })
        }).catch(action => {
        });
      }else{
        this.$message({
          type: 'info',
          message: '请选择记录'
        });
      }
    },
    // 新增报告提纲
    addreport () {
      this.newReportOutline = true
      this.options = []
      // 查询所有审计文书模板
      axios.post('http://localhost:7111/tOesRpt/queryTOesDocMould').then((response) => {
      console.log(response)
      if (response.data && Array.isArray(response.data) && response.data.length >0) {
        response.data.forEach(item => {
          this.options.push({
            id: item.docuMouldId,
            value: item.docuMouldId,
            label: item.docuMouldTitle
          })
        })
      }
      console.log(this.options)
    }).catch((response) => {
      console.log(response)
    })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    reportOutline() {
      if (this.value === '' || this.value === undefined || this.value === null) {
        this.$message.warning('请选择文书模板')
        return
      } else {
        this.$router.push({name:"auditnewreportcreate",query:{
          id: this.value
        }})
      }
    },
    lookSuggest() {
      this.showSuggest = true;
    },
    didi(myId, myinfo) {
      this.myflag = true;
      this.mytitle = myinfo;
      if (myId == '1') {
        this.reportContent = '多因素促粮食丰收 “粮食单产增加是多种因素综合作用的结果。”';
      } else if (myId == '2') {
        this.reportContent = '华为最新款5G手机，只要998！';
      } else if (myId == '3') {
        this.reportContent = '早饭只要8块钱，中午和晚上不吃饭都没问题';
      }
    },
    //跳转审计报告审核意见界面
    opinion(auditRptfileId,auditRptfileNm) {
      this.$router.push({
            name: 'opinion',
            query: {
              id : auditRptfileId,
              nm : auditRptfileNm
            }
          })
    },
  }
}
</script>

<style lang="less" scoped>
.content-cotainer {
  padding: 0 20px 20px 20px;
  height: 100%;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
}

.bg-purple {
  background: #d3dce6;
}

.my-font-height {
  line-height: 40px;
}
</style>
